<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('添加学员')"/>
</head>
<body class="gray-bg">
<form class="form-horizontal m" id="form-classes-addStudent">
    <div class="container-div">
        <div class="col-sm-12 search-collapse">
            <form id="export-form">
                <div class="select-list">
                    <ul>
                        <li>
                            <input type="hidden" name="params[classId]" th:value="${teachingClasses.classId}">
                            <input type="hidden" name="courseId" th:value="${teachingClasses.courseId}">
                            学生姓名：<input type="text" name="studentName" value=""/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm"
                               onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="row">
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
</form>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var classId = $.common.trim($("input[name !='classId']").val());
    var studentName = $.common.trim($("input[name='studentName']").val());
    var prefix = ctx + "teaching/apply";

    $(function () {
        var options = {
            url: prefix + "/list",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            rememberSelected: true,
            columns: [{
                checkbox: true
            },
                {
                    field: 'studentId',
                    title: '学生主键ID',
                    visible: false
                },
                {
                    field: 'studentName',
                    title: '学员姓名'
                },
                {
                    field: 'lessonRemain',
                    title: '剩余课时'
                },
                {
                    field: 'createTime',
                    title: '报名时间',
                    formatter: function (value, row, index) {
                        return $.common.dateFormat(value);
                    }

                }
            ]
        };
        $.table.init(options);
    });

    /* 添加用户-选择用户-提交 */
    function submitHandler() {
        var rows = $.table.selectFirstColumns();
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        addStudent(rows.join());
    }

    /* 添加到数据库 */
    function addStudent() {
        var studentId = $.table.selectFirstColumns();
        var classId = [[${teachingClasses.classId}]];
        $.ajax({
            type: "post",
            url: ctx + "teaching/students/add",
            data: {
                "studentId": studentId,
                "classId": classId,
            },
            success: function (result) {
                $.operate.successTabCallback(result);
            }
        });
    }
</script>
</body>
</html>
</body>
</html>
